<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class detail_aktifitas extends CI_Controller {

    function __construct() 
	{
        parent::__construct();
        $this->load->library('flexigrid');
        $this->load->library('form_validation');
		$this->load->library('session');
        $this->load->helper('flexigrid');
        $this->load->helper(array('form', 'url'));
		$this->load->model('evaluasi_model');
        $this->load->model('bagian_jenis_aktifitas_model');
    }

    //load Grid
    function index($id_evaluasi) 
	{
        if ($this->session->userdata('username') == NULL) 
		{
            redirect('login');
        } else {
            $colModel['no'] = array('No', 30, TRUE, 'center', 0);
			$colModel['nama_jenis_aktifitas'] = array('Jenis Aktifitas', 250, TRUE, 'center', 1);
            $colModel['nama_bagian_jenis_aktifitas'] = array('Bagian', 200, TRUE, 'center', 1);
			$colModel['Lihat_Satuan_Aktifitas'] = array('Lihat Satuan Aktifitas', 100, TRUE, 'center', 0);
			
            //get_santri_name
			$hasil = $this->evaluasi_model->get_nama_proyek($id_evaluasi);
			foreach ($hasil->result() as $row) 
			{
                $nama_evaluasi = $row->NAMA_EVALUASI;
				$proyek = $row->NAMA_PROYEK;
            }
			$this->session->set_userdata('ID_EVALUASI', $id_evaluasi);
			$this->session->set_userdata('NAMA_EVALUASI', $nama_evaluasi);

            $gridParams = array(
                'width' => 'auto',
                'height' => 300,
                'rp' => 10,
                'rpOptions' => '[5,10,15,20,25,40]',
                'pagestat' => 'Menampilkan: {from} hingga {to} dari {total} data.',
                'blockOpacity' => 0.5,
                'title' => 'Detail Jenis Aktifitas</br>Evaluasi : '.$nama_evaluasi.'</br>Proyek : '.$proyek.'',
                'showTableToggleBtn' => true
            );

			$buttons[] = array('separator');
            $buttons[] = array('Kembali ke Daftar Evaluasi', 'back', 'spt_js');

            // mengambil data dari file controler ajax pada method grid_foto
            $grid_js = build_grid_js('flex1', site_url("detail_aktifitas/grid_foto/".$id_evaluasi.""), $colModel, 'nama_jenis_aktifitas', 'desc', $gridParams, $buttons);

            $data['added_js'] =
                    "<script type='text/javascript'>
        function spt_js(com,grid)
        {              
				if (com=='Kembali ke Daftar Evaluasi')
                {
                        location.href='" . base_url() . "index.php/evaluasi/index/';
                }
        }
        </script>
        ";
		
            $data['js_grid'] = $grid_js;
            $data['content'] = $this->load->view('grid', $data, true);
            $this->load->view('main', $data);
        }
    }

    function grid_foto($id_evaluasi) 
	{
        $valid_fields = array('nama_jenis_aktifitas','nama_bagian_jenis_aktifitas');
        $this->flexigrid->validate_post('id_jenis_aktifitas', 'desc', $valid_fields);
        $records = $this->bagian_jenis_aktifitas_model->get_data_bagian_jenis_aktifitas_ja($id_evaluasi);
        $this->output->set_header($this->config->item('json_header'));		
        $no = 0;

        foreach ($records['records']->result() as $row) 
		{
			$kelas = str_replace("\'", "'", $row->nama_bagian_jenis_aktifitas);
            $record_items[] = array(
                $row->id_bagian_jenis_aktifitas,
                $no = $no + 1,
                $row->nama_jenis_aktifitas,
                $kelas,
				'<a href=\'' . base_url() . 'index.php/satuan_aktifitas/index/' . $row->id_bagian_jenis_aktifitas . '\'><img border=\'0\' src=\'' . base_url() . 'images/grid/folder.png\'></a> '
            );
        }

        if (isset($record_items))
            $this->output->set_output($this->flexigrid->json_build($records['record_count'], $record_items));
        else
            $this->output->set_output('{"page":"1","total":"0","rows":[]}');
    }
    

}
